package com.corpgovernment.organization.dataloader.db;

import com.corpgovernment.permission.entity.db.MbRole;
import com.corpgovernment.permission.mapper.RoleMapper;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import java.util.List;

/**
 * @author jhxue
 * @create 2022-02-23-11:22
 */
@Component
public class MbRoleLoader {

	@Autowired
	private RoleMapper roleMapper;

	public List<MbRole> selectRecManager(String corpId) {
		Example example = new Example(MbRole.class);
		Criteria criteria = example.createCriteria();
		criteria.andEqualTo("isRecManager", true);
		if (StringUtils.isBlank(corpId)) {
			criteria.andEqualTo("orgId", "");
		} else {
			criteria.andEqualTo("orgId", corpId);
		}
		criteria.andEqualTo("isDeleted", false);
		return roleMapper.selectByExample(example);
	}

	public List<MbRole> selectByRoleIdInfo(List<String> roleId) {
		Example example = new Example(MbRole.class);
		example.createCriteria().andIn("id", roleId).andEqualTo("isDeleted", false);
		return roleMapper.selectByExample(example);
	}
}
